package com.community.web.master.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.community.model.entity.Complaint;
import com.community.web.master.domain.dto.PageComplaintDto;
import com.community.web.master.domain.vo.PageResult;
import com.community.web.master.mapper.ComplaintMapper;
import com.community.web.master.service.IComplaintService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 李晶
 * @since 2024-07-02
 */
@Service
public class ComplaintServiceImpl extends ServiceImpl<ComplaintMapper, Complaint> implements IComplaintService {
    @Autowired
    ComplaintMapper complaintMapper;

    /**
     * 分页查询
     * @param pageComplaintDto
     * @return
     */
    @Override
    public PageResult pageQuery(PageComplaintDto pageComplaintDto) {
        IPage<Complaint> page = new Page<Complaint>(pageComplaintDto.getPage(),pageComplaintDto.getPageSize());
        QueryWrapper<Complaint> queryWrapper = new QueryWrapper<>();
        System.out.println(page.getCurrent()+" "+page.getSize());
        //如果有status条件,
        if (pageComplaintDto.getComplaintStatus() != null) {
            queryWrapper.eq("complaint_status", pageComplaintDto.getComplaintStatus());
        }

        //查询
        complaintMapper.selectPage(page,queryWrapper);
        PageResult pageResult = new PageResult(page.getTotal(),page.getRecords());
        return pageResult;
    }

    /**
     * 修改状态
     * @param id
     */
    @Override
    public void updateStatus(Integer id) {
        Complaint complaint = new Complaint();
        complaint.setComplaintStatus(1);
        QueryWrapper<Complaint> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("id",id);
        complaintMapper.update(complaint,queryWrapper);
    }
}
